<template>
  <div>
    <div class="prescription-info-wrapper">
      <div class="title">处方信息</div>
      <div class="line-con">
        <div class="label">用药人姓名：</div>
        <div class="line-detail">
          <span>{{ detailData.medical_patient.real_name }}</span>
        </div>
      </div>
      <div class="line-con">
        <div class="label">身份证号：</div>
        <div class="line-detail">
          <span>{{ detailData.medical_patient.id_no }}</span>
        </div>
      </div>
      <div class="line-con">
        <div class="label">出生年月：</div>
        <div class="line-detail">
          <span>{{ detailData.medical_patient.f_birthday }}</span>
        </div>
      </div>
      <div class="line-con">
        <div class="label">性别：</div>
        <div class="line-detail">
          <span>{{ detailData.medical_patient.f_gender }}</span>
        </div>
      </div>
      <div class="line-con">
        <div class="label">手机号码：</div>
        <div class="line-detail">
          <span>{{ detailData.medical_patient.phone }}</span>
        </div>
      </div>
      <div class="line-con">
        <div class="label">疾病史：</div>
        <div class="line-detail">
          <p><span class="left">过往病史：</span><span>{{ detailData.medical_patient.f_past_medical_history }}</span></p>
          <p><span class="left">过敏史：</span>{{ detailData.medical_patient.f_allergic_history }}</p>
          <p><span class="left">家族病史：</span>{{ detailData.medical_patient.f_family_medical_history }}</p>
          <p><span class="left">肝功能：</span>{{ detailData.medical_patient.f_liver_function }}</p>
          <p><span class="left">肾功能：</span>{{ detailData.medical_patient.f_renal_function }}</p>
          <p><span class="left">妊娠哺育：</span>{{ detailData.medical_patient.f_pregnancy_status }}</p>
        </div>
      </div>
      <div class="line-con" v-if="detailData.medical_verify_status == 2">
        <div class="label">审核未通过原因：</div>
        <div class="line-detail">
          <span>{{ detailData.reasons_for_failure }}</span>
        </div>
      </div>
      <div class="electronic-prescription" v-if="detailData.medical_verify_status == 1 && detailData.prescription_path">
        <div class="label">电子处方单（点击查看大图）</div>
        <img class="prescription-img" :src="detailData.prescription_path" @click="showBigImage('prescription_path')">
      </div>
    </div>
    <div class="bottom-btn" v-if="detailData.medical_verify_status == 1">
      <div class="bottom-btn-box">
        <van-button class="btn border" round @click="showBigImage('prescription_note_path')">电子处方单</van-button>
      </div>
    </div>
    <!-- 处方笺 预览 -->
    <van-popup
      v-model="show_big_image"
      closeable
      class="big-prescription-img"
    >
      <div class="img-box">
        <img :src="big_img_path" alt="">
      </div>
      <div class="save-img-btn" @click="saveImg(big_img_path)">保存图片~</div>
    </van-popup>
  </div>
</template>

<script>
import Vue from 'vue'
import { Popup } from 'vant'
import { PrescriptionDetail } from '@/api/dz/dzPrescriptionDrug'
import small from '@/smallapp/small'

Vue.use(Popup)
export default {
  props: {
    detailAll: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  data() {
    return {
      show_big_image: false,
      big_img_path: '',
      big_img_name: ''
    }
  },
  methods: {
    showBigImage(name) {
      if (name === 'prescription_path') {
        this.show_big_image = true
        this.big_img_name = '电子处方单'
        this.big_img_path = this.detailData.prescription_path
      } else if (name === 'prescription_note_path') {
        this.$loadingWrap.show()
        PrescriptionDetail({ order_id: this.detailData.order_id }).then(res => {
          this.$loadingWrap.close()
          if (res.status == 1) {
            this.show_big_image = true
            this.big_img_path = res.data
            this.big_img_name = '处方笺'
          } else {
            this.$Error(res.msg)
          }
        })
      }
    },
    saveImg(path) {
      small.saveImage(path)
    }
  },
  computed: {
    detailData() {
      return this.detailAll.detail
    }
  }
}
</script>

<style lang="scss">
.prescription-info-wrapper {
  width: 100%;
  background: #fff;
  box-sizing: border-box;
  padding: 30px;
  .title {
    position: relative;
    padding-left: 0.24rem;
    font-size: 0.373333rem;
    font-weight: bold;
    margin-bottom: 10px;
    &::before {
      content: "";
      position: absolute;
      top: 0.106667rem;
      left: 0;
      width: 0.08rem;
      height: 0.346667rem;
      background: #F30C23;
    }
  }
  .line-con {
    display: flex;
    padding: 30px 0;
    &:last-child {
      padding-bottom: 0;
    }
    .label {
      width: 200px;
    }
    .line-detail {
      flex: 1;
      text-align: left;
      p {
        line-height: 30px;
        display: flex;
        padding: 10px 0;
        .left {
          // text-align: right;
          width: 150px;
          flex-shrink: 0;
        }
      }
    }
  }
  .electronic-prescription {
    padding: 30px 0;
    .prescription-img {
      max-width: 320px;
      margin: 30px 0 0 30px;
    }
  }
}
.big-prescription-img {
  width: 100%;
  height: 100%;
  background-color: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  .van-popup__close-icon {
    font-size: 50px !important;
  }
  .img-box {
    width: 100%;
    max-height: 85%;
    padding: 24px;
    display: flex;
    justify-content: center;
    align-items: center;
    img{
      max-width: 100%;
      max-height: 100%;
      height: auto;
    }
  }
  .save-img-btn {
    width: 80%;
    background: #EF6666;
    padding: 30px 60px;
    color: #fff;
    border-radius: 50px;
    white-space: nowrap;
    text-align: center;
    margin: 20px auto 0;
  }
}
.bottom-btn {
  position: fixed;
  left: 0;
  bottom: 0;
  width: 100%;
  // height:98px;
  padding: 0 16px;
  font-size: 0;
  background: #fff;
  text-align: right;
  padding-bottom: constant(safe-area-inset-bottom); /*兼容 IOS<11.2*/
  padding-bottom: env(safe-area-inset-bottom); /*兼容 IOS>11.2*/
  &-box {
    padding: 12px 0;
    border-bottom: 1px solid #f5f5f5;
    &:last-child {
      border-bottom: none;
    }
  }
  .inline-block {
    display: inline-block;
  }
  .btn {
    width: 166px;
    height: 72px;
    margin: 0 6px;
    font-size: 28px;
    color: #fff;
    background: linear-gradient(
      -90deg,
      rgba(233, 1, 4, 1),
      rgba(254, 27, 73, 1)
    );
    &.no-border {
      border: 0;
    }
    &.border {
      border: 1px solid #ffaf4f;
      background: #fff;
      color: #ffaf4f;
    }
    &.refunding-btn {
      border-color: #b3b3b3;
      color: #666666;
      background: #fff;
      img {
        width: 24px;
        height: 24px;
        margin-right: 12px;
      }
    }
    &.share-price {
      background: linear-gradient(
        90deg,
        rgba(255, 174, 0, 1),
        rgba(255, 138, 2, 1)
      );
    }
  }
}
</style>